using System;
using System.Collections;
using AopAlliance.Intercept;

namespace Sedna.Core.Event
{
    public class EventHandlerRegistry: IEventHandlerRegistry
    {
        private IList handlers;

        public IList Handlers
        {
            set { handlers = value; }
        }

        public bool CanHandle(string eventName)
        {
            foreach (IEventHandler handler in handlers)
            {
                if (handler.CanHandle(eventName))
                    return true;
            }
            return false;
        }

        public bool HandleEvent(EventfulAttribute eventfulAttribute, IMethodInvocation invocation,
                                object invocationResult)
        {
            bool result = false;
            foreach (IEventHandler handler in handlers)
            {
                if (handler.CanHandle(eventfulAttribute.Name))
                {
                    handler.Handle(eventfulAttribute, invocation, invocationResult);
                    result = true;
                }
            }
            return result;
        }
    }
}
